package com.huanglj.taobaounion.ui.adapter;

import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.PagerAdapter;

import com.huanglj.taobaounion.model.domain.Categories;
import com.huanglj.taobaounion.ui.fragment.HomePagerFragment;
import com.huanglj.taobaounion.utils.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * 这个是页面切换的fragment
 *
 */

public class HomeAdapter extends FragmentPagerAdapter {

    private static final String TAG = "HomeAdapter";

    private List<Categories.DataBean> mDataBeans = new ArrayList<>();

    public HomeAdapter(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mDataBeans.get(position).getTitle();
    }

    @Override
    public int getCount() {
        return mDataBeans.size();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Categories.DataBean dataBean = mDataBeans.get(position);
        HomePagerFragment homePagerFragment = new HomePagerFragment(dataBean);
        LogUtil.d(TAG,"you get fragment");
        return homePagerFragment;
    }


    public void setData(List<Categories.DataBean> data) {
        if (data != null) {
            mDataBeans.addAll(data);
            notifyDataSetChanged();
            LogUtil.d(TAG,"Adapter data size :" + mDataBeans.size());
        }

    }
}
